{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyqpanda.Hamiltonian import (PauliOperator, \n",
    "                                  chem_client)\n",
    "from pyqpanda.Hamiltonian.QubitOperator import *\n",
    "from pyqpanda import *\n",
    "from pyqpanda.utils import *\n",
    "from pyqpanda.Algorithm.hamiltonian_simulation import *\n",
    "\n",
    "geometry=[['N',[0,0,0]], ['N',[0,0,0.74]]]\n",
    "\n",
    "\n",
    "basis=\"sto-3g\"\n",
    "multiplicity=1\n",
    "charge=0\n",
    "run_mp2=True\n",
    "run_cisd=True\n",
    "run_ccsd=True\n",
    "run_fci=True\n",
    "\n",
    "str1=chem_client(\n",
    "        geometry=geometry,\n",
    "        basis=basis,\n",
    "        multiplicity=multiplicity,\n",
    "        charge=charge,\n",
    "        run_mp2=run_mp2,\n",
    "        run_cisd=run_cisd,\n",
    "        run_ccsd=run_ccsd,\n",
    "        run_fci=run_fci,\n",
    "        hamiltonian_type=\"pauli\")\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2239\n"
     ]
    }
   ],
   "source": [
    "#print(str1)\n",
    "s=str1.split('\\n')\n",
    "print(len(s))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true,
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "# convert to PauliOperator\n",
    "\n",
    "def convert_operator(str):\n",
    "    terms=str.split(' +\\n')\n",
    "    tuplelist=dict()\n",
    "    for term in terms:\n",
    "        data=term.split(' ',1)        \n",
    "        tuplelist[data[1][1:-1]]=eval(data[0])\n",
    "\n",
    "    operator=PauliOperator(tuplelist)    \n",
    "    return operator"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from numpy.linalg import eig\n",
    "# definition of to_dense\n",
    "Z=np.array([[1,0],[0,-1]])\n",
    "X=np.array([[0,1],[1,0]])\n",
    "Y=np.array([[0,-1j],[1j,0]])\n",
    "I=np.eye(2)\n",
    "\n",
    "pauli_mat={'I':I,'X':X,'Y':Y,'Z':Z}\n",
    "\n",
    "def krons(matlist):\n",
    "    mat=np.array([1])\n",
    "    for term in matlist:\n",
    "        mat=np.kron(mat,term)\n",
    "        \n",
    "    return mat\n",
    "\n",
    "def get_dense_pauli(pauli_tuple, n_qubit):\n",
    "    result=np.array([1],dtype='complex128')\n",
    "    for i in range(n_qubit):\n",
    "        if i == pauli_tuple[1]:\n",
    "            result=np.kron(result, pauli_mat[pauli_tuple[0]])\n",
    "        else:\n",
    "            result=np.kron(result,I)\n",
    "    return result\n",
    "\n",
    "def get_matrix(pauliOperator):\n",
    "    op=pauliOperator.ops\n",
    "    n_qubit=pauliOperator.get_qubit_count()\n",
    "    \n",
    "    #preparation for numpy array\n",
    "    I_=np.eye(1<<n_qubit,dtype='complex128')\n",
    "    result=np.zeros((1<<n_qubit,1<<n_qubit),dtype='complex128')\n",
    "    \n",
    "    for term in op:\n",
    "        one_term_result=deepcopy(I_)\n",
    "        tuplelist=PauliOperator.parse_pauli(term)\n",
    "        for pauli_tuple in tuplelist:\n",
    "            one_term_result=one_term_result.dot(get_dense_pauli(pauli_tuple,n_qubit))\n",
    "        result+=one_term_result*op[term]\n",
    "    return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 / 50\n",
      "2 / 50\n",
      "3 / 50\n",
      "4 / 50\n",
      "5 / 50\n",
      "6 / 50\n",
      "7 / 50\n",
      "8 / 50\n",
      "9 / 50\n",
      "10 / 50\n",
      "11 / 50\n",
      "12 / 50\n",
      "13 / 50\n",
      "14 / 50\n",
      "15 / 50\n",
      "16 / 50\n",
      "17 / 50\n",
      "18 / 50\n",
      "19 / 50\n",
      "20 / 50\n",
      "21 / 50\n",
      "22 / 50\n",
      "23 / 50\n",
      "24 / 50\n",
      "25 / 50\n",
      "26 / 50\n",
      "27 / 50\n",
      "28 / 50\n",
      "29 / 50\n",
      "30 / 50\n",
      "31 / 50\n",
      "32 / 50\n",
      "33 / 50\n",
      "34 / 50\n",
      "35 / 50\n",
      "36 / 50\n",
      "37 / 50\n",
      "38 / 50\n",
      "39 / 50\n",
      "40 / 50\n",
      "41 / 50\n",
      "42 / 50\n",
      "43 / 50\n",
      "44 / 50\n",
      "45 / 50\n",
      "46 / 50\n",
      "47 / 50\n",
      "48 / 50\n",
      "49 / 50\n",
      "50 / 50\n"
     ]
    }
   ],
   "source": [
    "# try to reconstruct the H2 energy\n",
    "\n",
    "def H2_energy_from_distance(distance):\n",
    "    geometry=[['H',[0,0,0]], ['H',[0,0,distance]]]\n",
    "    \n",
    "    basis=\"sto-3g\"\n",
    "    multiplicity=1\n",
    "    charge=0\n",
    "    run_mp2=True\n",
    "    run_cisd=True\n",
    "    run_ccsd=True\n",
    "    run_fci=True\n",
    "\n",
    "    str1=chem_client(\n",
    "            geometry=geometry,\n",
    "            basis=basis,\n",
    "            multiplicity=multiplicity,\n",
    "            charge=charge,\n",
    "            run_mp2=run_mp2,\n",
    "            run_cisd=run_cisd,\n",
    "            run_ccsd=run_ccsd,\n",
    "            run_fci=run_fci,\n",
    "            hamiltonian_type=\"pauli\")\n",
    "    \n",
    "    pauli_op=convert_operator(str1)\n",
    "    matrix_=get_matrix(pauli_op)\n",
    "    eigval,_=eig(matrix_)\n",
    "    return min(eigval).real\n",
    "\n",
    "distance_range=np.linspace(0.25,2.5,50)\n",
    "energy=np.zeros(len(distance_range))\n",
    "\n",
    "for i,distance in enumerate(distance_range):\n",
    "    print('{} / {}'.format(i+1,len(distance_range)))\n",
    "    energy[i]=H2_energy_from_distance(distance)\n",
    "    \n",
    "from matplotlib.pyplot import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [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uQRtfPP5mOb5\nmL3Ph3NOtyRuQBrwCrAcyAD2AudOaHMb8G2va52j8/Eu4ALgwCTvvxd4FDDgIuAZr2v2+HxcBvzS\n6zrn6FyUAxfEH+cBhxL8rvjm8zHN8zFrnw/1/JO3BTjinHvVOTcK3Atc73FNnnHOPQl0naHJ9cCP\n3Lg/AIVmVj431c29aZwP33DOtTjnno8/7gPqgYoJzXzz+Zjm+Zg1Cv/kVQANpz1vJPE/4Ifi/419\nwMyq5qa0eWm658tPLjazvWb2qJmt87qYuWBmNcD5wDMT3vLl5+MM5wNm6fOh8E+eJXht4hSqXwA1\nzrkNwE7gnlmvav6azvnyk+cZvxx/I/At4CGP65l1ZpYL/Az4z8653olvJ/gjKf35mOJ8zNrnQ+Gf\nvEbg9J58JdB8egPnXKdzbiT+9F+BzXNU23w05fnyE+dcr3OuP/74ESDdzEo8LmvWmFk640H3Y+fc\ngwma+OrzMdX5mM3Ph8I/ebuBlWa2zMwygJuB7ac3mDBm+QHGx/b8ajvwJ/FZHRcBPc65Fq+L8oqZ\nLTYziz/ewvjvZKe3Vc2O+N/z+0C9c+5rkzTzzedjOudjNj8fwZn4IX7mnIuY2WeAXzM+8+cHzrmD\nZva3QJ1zbjvwWTP7ABBh/Mu/2zwreJaZ2U8Zn6FQYmaNwP8A0gGcc98BHmF8RscRYBD4hDeVzo1p\nnI+bgE+bWQQYAm528WkeKWgr8HFgv5ntib/210A1+PLzMZ3zMWufD13hKyLiQxr2ERHxIYW/iIgP\nKfxFRHxI4S8i4kMKfxERH1L4i4j4kMJfRMSHFP4iIj70/wFVNoxWpoMvOQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1f50bacd630>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "-0.93605491984427658"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plot(distance_range,energy)\n",
    "show()\n",
    "\n",
    "energy[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'Y0 Z1 X2': 0.5j, 'X0 Z1 X2': (0.5+0j), 'Y0 Z1 Y2': (0.5+0j), 'X0 Z1 Y2': -0.5j, 'Y0 Z1 Z2 X3': 0.5j, 'X0 Z1 Z2 X3': (0.5+0j), 'Y0 Z1 Z2 Y3': (0.5+0j), 'X0 Z1 Z2 Y3': -0.5j, 'Y1 X2': 0.5j, 'X1 X2': (0.5+0j), 'Y1 Y2': (0.5+0j), 'X1 Y2': -0.5j, 'Y1 Z2 X3': 0.5j, 'X1 Z2 X3': (0.5+0j), 'Y1 Z2 Y3': (0.5+0j), 'X1 Z2 Y3': -0.5j}\n"
     ]
    }
   ],
   "source": [
    "Atom_Name=['H', 'He', 'Li', 'Be', 'B', 'C', 'N', 'O', 'F', 'He', 'Na', 'Mg', 'Al', 'Si', 'P', 'S', 'Cl']\n",
    "Atom_Electron=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]\n",
    "Atom_Dict=dict()\n",
    "for i in range(len(Atom_Name)):\n",
    "    Atom_Dict[Atom_Name[i]]=Atom_Electron[i]\n",
    "    \n",
    "def get_electron_count(geometry):\n",
    "    n_electron = 0\n",
    "    for atom in geometry:\n",
    "        n_electron+=Atom_Dict[atom[0]]\n",
    "    return n_electron\n",
    "\n",
    "operator=convert_operator(str1)\n",
    "n_qubit = operator.get_qubit_count()\n",
    "n_electron=get_electron_count(geometry)\n",
    "\n",
    "def get_fermion_jordan_wigner(fermion_type, op_qubit):\n",
    "    '''\n",
    "    fermion_op = ('a',1) or ('c',1)\n",
    "    'a' is for annihilation\n",
    "    'c' is for creation\n",
    "    '''\n",
    "    opstr=''\n",
    "    for i in range(op_qubit):\n",
    "        opstr=opstr+'Z'+str(i)+' '\n",
    "    \n",
    "    opstr1=opstr+'X'+str(op_qubit)\n",
    "    opstr2=opstr+'Y'+str(op_qubit)\n",
    "    if fermion_type == 'a':\n",
    "        return PauliOperator({opstr1:1,opstr2:1j})\n",
    "    elif fermion_type == 'c':\n",
    "        return PauliOperator({opstr1:1,opstr2:-1j})\n",
    "    else:\n",
    "        assert False\n",
    "        \n",
    "def get_ccs_n_term(n_qubit, n_electron):\n",
    "    if n_electron>n_qubit:\n",
    "        assert False\n",
    "    elif n_electron==n_qubit:\n",
    "        return 0\n",
    "    param_n=0\n",
    "    # ccsd is each electron jump to the excited level, and also each two\n",
    "    result_op=PauliOperator(dict())\n",
    "    for i in range(n_electron):\n",
    "        for ex in range(n_electron, n_qubit):\n",
    "            param_n+=1\n",
    "                    \n",
    "    return param_n\n",
    "\n",
    "def get_ccsd_n_term(n_qubit, n_electron):\n",
    "    if n_electron>n_qubit:\n",
    "        assert False\n",
    "    elif n_electron==n_qubit:\n",
    "        return 0\n",
    "    param_n=0\n",
    "    # ccsd is each electron jump to the excited level, and also each two\n",
    "    result_op=PauliOperator(dict())\n",
    "    for i in range(n_electron):\n",
    "        for ex in range(n_electron, n_qubit):\n",
    "            param_n+=1\n",
    "    \n",
    "    for i in range(n_electron):\n",
    "        for j in range(i+1,n_electron):\n",
    "            for ex1 in range(n_electron,n_qubit):\n",
    "                for ex2 in range(ex1+1,n_qubit):\n",
    "                    param_n+=1\n",
    "                    \n",
    "    return param_n\n",
    "\n",
    "def get_ccs(n_qubit, n_electron, param_list):\n",
    "    if n_electron>n_qubit:\n",
    "        assert False\n",
    "    elif n_electron==n_qubit:\n",
    "        return PauliOperator(dict())\n",
    "    param_n=0\n",
    "    # ccsd is each electron jump to the excited level, and also each two\n",
    "    result_op=PauliOperator(dict())\n",
    "    for i in range(n_electron):\n",
    "        for ex in range(n_electron, n_qubit):\n",
    "            result_op+=get_fermion_jordan_wigner('c',ex)*get_fermion_jordan_wigner('a',i)*param_list[param_n]\n",
    "            param_n+=1\n",
    "            \n",
    "    return result_op\n",
    "        \n",
    "def get_ccsd(n_qubit, n_electron, param_list):\n",
    "    if n_electron>n_qubit:\n",
    "        assert False\n",
    "    elif n_electron==n_qubit:\n",
    "        return PauliOperator(dict())\n",
    "    param_n=0\n",
    "    # ccsd is each electron jump to the excited level, and also each two\n",
    "    result_op=PauliOperator(dict())\n",
    "    for i in range(n_electron):\n",
    "        for ex in range(n_electron, n_qubit):\n",
    "            result_op+=get_fermion_jordan_wigner('c',ex)*get_fermion_jordan_wigner('a',i)*param_list[param_n]\n",
    "            param_n+=1\n",
    "    \n",
    "    for i in range(n_electron):\n",
    "        for j in range(i+1,n_electron):\n",
    "            for ex1 in range(n_electron,n_qubit):\n",
    "                for ex2 in range(ex1+1,n_qubit):\n",
    "                    result_op+=get_fermion_jordan_wigner('c',ex2)* \\\n",
    "                               get_fermion_jordan_wigner('c',ex1)* \\\n",
    "                               get_fermion_jordan_wigner('a',j)*   \\\n",
    "                               get_fermion_jordan_wigner('a',i)* param_list[param_n]\n",
    "                    param_n+=1\n",
    "                    \n",
    "    return result_op\n",
    "                \n",
    "n_param=get_ccs_n_term(n_qubit,n_electron)\n",
    "paramlist=np.ones(n_param)*0.5\n",
    "op1=get_ccs(n_qubit,n_electron,paramlist)\n",
    "print(op1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'Y0 Z1 X2': (-1+0j), 'X0 Z1 Y2': (1+0j), 'Y0 Z1 Z2 X3': (-1+0j), 'X0 Z1 Z2 Y3': (1+0j), 'Y1 X2': (-1+0j), 'X1 Y2': (1+0j), 'Y1 Z2 X3': (-1+0j), 'X1 Z2 Y3': (1+0j)}\n"
     ]
    }
   ],
   "source": [
    "def dagger(pauliOperator):\n",
    "    new_ops=deepcopy(pauliOperator.ops)\n",
    "    for term in new_ops:\n",
    "        new_ops[term]=new_ops[term].real-new_ops[term].imag*1j\n",
    "    return PauliOperator(new_ops)\n",
    "\n",
    "def cc_to_ucc_hamiltonian(cc_op):\n",
    "    return 1j*(cc_op-dagger(cc_op))\n",
    "\n",
    "ucc=cc_to_ucc_hamiltonian(op1)\n",
    "print(ucc)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1.5+0j)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "complex(1.5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'': (-0.09706627236102515+0j), 'X0 X1 Y2 Y3': (-0.04530261554936542+0j), 'X0 Y1 Y2 X3': (0.04530261554936542+0j), 'Y0 X1 X2 Y3': (0.04530261554936542+0j), 'Y0 Y1 X2 X3': (-0.04530261554936542+0j), 'Z0': (0.17141282594679685+0j), 'Z0 Z1': (0.16868898154816542+0j), 'Z0 Z2': (0.1206252346467246+0j), 'Z0 Z3': (0.16592785019609002+0j), 'Z1': (0.17141282594679685+0j), 'Z1 Z2': (0.16592785019609002+0j), 'Z1 Z3': (0.1206252346467246+0j), 'Z2': (-0.22343153540326133+0j), 'Z2 Z3': (0.17441287597259206+0j), 'Z3': (-0.22343153540326133+0j)}\n"
     ]
    }
   ],
   "source": [
    "print(convert_operator(str1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'Y0 Z1 X2': -1.0, 'X0 Z1 Y2': 1.0, 'Y0 Z1 Z2 X3': -1.0, 'X0 Z1 Z2 Y3': 1.0, 'Y1 X2': -1.0, 'X1 Y2': 1.0, 'Y1 Z2 X3': -1.0, 'X1 Z2 Y3': 1.0}\n"
     ]
    }
   ],
   "source": [
    "def flatten(pauliOperator):\n",
    "    new_ops=deepcopy(pauliOperator.ops)\n",
    "    for term in new_ops:\n",
    "        if abs(new_ops[term].imag)<pauliOperator.m_error_threshold:\n",
    "            new_ops[term]=float(new_ops[term].real)\n",
    "        else:\n",
    "            assert False\n",
    "    return PauliOperator(new_ops)\n",
    "ucc=flatten(ucc)\n",
    "print(ucc)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4\n"
     ]
    }
   ],
   "source": [
    "init()\n",
    "prog=QProg()\n",
    "q=qAlloc_many(n_qubit)\n",
    "c=cAlloc_many(n_qubit)\n",
    "print(n_qubit)\n",
    "#prog.insert(simulate_hamiltonian(qubit_list=q,pauliOperator=ucc,t=1.,slices=3))\n",
    "#print(to_qrunes(prog))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#QUBITS_NUM 4\n",
      "#CREGS_NUM 4\n",
      "RX 0,\"1.570796\"\n",
      "H 2\n",
      "\n"
     ]
    }
   ],
   "source": [
    "def transform_base(qubitlist,base):\n",
    "    qcircuit=QCircuit()\n",
    "    for i in range(0,len(base),3):\n",
    "        if base[i]=='X':\n",
    "            qcircuit.insert(H(qubitlist[int(base[i+1])]))\n",
    "        elif base[i]=='Y':\n",
    "            qcircuit.insert(RX(qubitlist[int(base[i+1])],pi/2))\n",
    "        elif base[i]=='Z':\n",
    "            pass\n",
    "        else:\n",
    "            assert False\n",
    "    return qcircuit\n",
    "base='Y0 Z1 X2'\n",
    "prog1=QProg()\n",
    "prog1.insert(transform_base(q,base))\n",
    "print(to_qrunes(prog1))   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def parity_check(string, paulis):\n",
    "    check=0\n",
    "    \n",
    "    tuplelist=PauliOperator.parse_pauli(paulis)\n",
    "    qubit_idx_list=list()\n",
    "    for term in tuplelist:\n",
    "        qubit_idx_list.append(term[1])\n",
    "    \n",
    "    for i in qubit_idx_list:\n",
    "        if string[i]=='1':\n",
    "            check+=1\n",
    "    \n",
    "    return check%2        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.21184402862066373\n"
     ]
    }
   ],
   "source": [
    "#e.g. component=('X0 Y1 Z2',0.33)\n",
    "def get_expectation(qubit_number,unitaryCC,component,shots_):\n",
    "    init()\n",
    "    prog=QProg()\n",
    "    q=qAlloc_many(qubit_number)\n",
    "    c=cAlloc_many(qubit_number)\n",
    "    prog.insert(RX(q[0],pi)).insert(RX(q[2],pi))\n",
    "    #print(unitaryCC)\n",
    "    prog.insert(simulate_hamiltonian(qubit_list=q,pauliOperator=unitaryCC,t=1,slices=3))\n",
    "    if component[0]!='':\n",
    "        prog.insert(transform_base(q,component[0]))\n",
    "    #print(to_qrunes(prog))\n",
    "    directly_run(QProg=prog)\n",
    "    result=get_probabilites(q, select_max=-1, dataType=\"dict\")\n",
    "    finalize()\n",
    "    expectation=0\n",
    "    for i in result:\n",
    "        if parity_check(i, component[0]):\n",
    "            expectation-=result[i]\n",
    "        else:\n",
    "            expectation+=result[i]       \n",
    "    #print(result)\n",
    "    return expectation*component[1]\n",
    "    \n",
    "    '''\n",
    "    result=quick_measure(q, shots_)\n",
    "    finalize()\n",
    "    #print(result)\n",
    "    expectation=0\n",
    "    for i in result:\n",
    "        if parity_check(i, component[0]):\n",
    "            expectation-=result[i]\n",
    "        else:\n",
    "            expectation+=result[i]\n",
    "    expectation=float(expectation)       \n",
    "    return expectation/shots_*component[1]\n",
    "    '''\n",
    "\n",
    "qubit_number=4\n",
    "electron_number=2\n",
    "#initial stata\n",
    "n_param=get_ccs_n_term(qubit_number,electron_number)\n",
    "#initial parameter\n",
    "paramlist=np.ones(n_param)*0.1\n",
    "op1=get_ccs(n_qubit,n_electron,paramlist)\n",
    "ucc=cc_to_ucc_hamiltonian(op1)\n",
    "ucc=flatten(ucc)\n",
    "component=('Z0 Z1 Z2',0.23)\n",
    "exp=get_expectation(qubit_number,ucc,component,shots_=1000)\n",
    "print(exp)\n",
    " "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(-0.3886816248605904+0j)\n"
     ]
    }
   ],
   "source": [
    "def vqe_subroutine(qubit_number_,electron_number,Hamiltonian,unitaryCC_,shots):\n",
    "    #initial stata\n",
    "    #print(Hamiltonian.ops)\n",
    "    #matrix=get_matrix(Hamiltonian)\n",
    "    #eigv,eigg=eig(matrix)\n",
    "    #print(eigv)\n",
    "    #print(eigg)\n",
    "    expectation=0\n",
    "    for component in Hamiltonian.ops:\n",
    "        #print(component)\n",
    "        temp=(component,Hamiltonian.ops[component])\n",
    "        expectation+=get_expectation(qubit_number=qubit_number_,unitaryCC=unitaryCC_,component=temp,shots_=shots)\n",
    "    return expectation\n",
    "\n",
    "qubit_number=4\n",
    "electron_number=2\n",
    "n_param=get_ccs_n_term(qubit_number,electron_number)\n",
    "#initial parameter\n",
    "paramlist=np.ones(n_param)*0.5\n",
    "op1=get_ccs(n_qubit,n_electron,paramlist)\n",
    "ucc=cc_to_ucc_hamiltonian(op1)\n",
    "ucc=flatten(ucc)\n",
    "exp= vqe_subroutine(qubit_number,electron_number,convert_operator(str1),unitaryCC_=ucc,shots=1000)\n",
    "print(exp)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-1.111296028524694\n",
      "   direc: array([[ 1.        ,  0.        ,  0.        ,  0.        ],\n",
      "       [ 0.00877657,  0.86339178, -0.534511  ,  0.13091851],\n",
      "       [ 0.        ,  0.        ,  1.        ,  0.        ],\n",
      "       [-0.32939813,  0.09675982, -0.0252938 , -0.4609624 ]])\n",
      "     fun: array(-1.111296028524694)\n",
      " message: 'Optimization terminated successfully.'\n",
      "    nfev: 436\n",
      "     nit: 9\n",
      "  status: 0\n",
      " success: True\n",
      "       x: array([ -1.10219205e-03,   3.14138200e+00,  -7.86089527e-01,\n",
      "         1.87800369e-03])\n"
     ]
    }
   ],
   "source": [
    "from scipy.optimize import minimize\n",
    "from functools import partial\n",
    "def binding(qubit_number,electron_number,Hamiltonian,shots):\n",
    "    return partial(vqe_in_list,\n",
    "                    qubit_number=qubit_number,\n",
    "                    electron_number=electron_number,\n",
    "                    Hamiltonian=Hamiltonian,\n",
    "                    shots=shots)\n",
    "def vqe_in_list(arguments,qubit_number,electron_number,Hamiltonian,shots):\n",
    "    op1=get_ccs(n_qubit,n_electron,arguments)\n",
    "    ucc=cc_to_ucc_hamiltonian(op1)\n",
    "    ucc=flatten(ucc)\n",
    "    expectation=0\n",
    "    for component in Hamiltonian.ops:\n",
    "        #print(component)\n",
    "        temp=(component,Hamiltonian.ops[component])\n",
    "        expectation+=get_expectation(qubit_number=qubit_number,unitaryCC=ucc,component=temp,shots_=shots)\n",
    "    expectation=float(expectation.real)\n",
    "    return expectation\n",
    "def H2_vqe_subprocess(distance):\n",
    "    geometry=[['H',[0,0,0]], ['H',[0,0,distance]]]\n",
    "    \n",
    "    basis=\"sto-3g\"\n",
    "    multiplicity=1\n",
    "    charge=0\n",
    "    run_mp2=True\n",
    "    run_cisd=True\n",
    "    run_ccsd=True\n",
    "    run_fci=True\n",
    "\n",
    "    str1=chem_client(\n",
    "            geometry=geometry,\n",
    "            basis=basis,\n",
    "            multiplicity=multiplicity,\n",
    "            charge=charge,\n",
    "            run_mp2=run_mp2,\n",
    "            run_cisd=run_cisd,\n",
    "            run_ccsd=run_ccsd,\n",
    "            run_fci=run_fci,\n",
    "            hamiltonian_type=\"pauli\")\n",
    "    \n",
    "    Hamiltonian=convert_operator(str1)\n",
    "    n_qubit = Hamiltonian.get_qubit_count()\n",
    "    n_electron=get_electron_count(geometry)\n",
    "    n_param=get_ccs_n_term(n_qubit,n_electron)\n",
    "    #initial_guess\n",
    "    initial_guess=np.ones(n_param)*0.5\n",
    "    result=minimize(binding(n_qubit,n_electron,Hamiltonian,5000),initial_guess,method=\"Powell\")\n",
    "    return result\n",
    "result=H2_vqe_subprocess(0.64)\n",
    "a=result.fun\n",
    "print(a)\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "-0.304860985839\n",
      "1\n",
      "-0.574646914091\n",
      "2\n",
      "-0.754882641632\n",
      "3\n",
      "-0.878435737257\n",
      "4\n",
      "-0.963911459316\n",
      "5\n",
      "-1.02308332718\n",
      "6\n",
      "-1.06342503461\n",
      "7\n",
      "-1.08996237472\n",
      "8\n",
      "-1.1062422953\n",
      "9\n",
      "-1.11479188236\n",
      "10\n",
      "-1.11747399524\n",
      "11\n",
      "-1.11575238482\n",
      "12\n",
      "-1.11069207905\n",
      "13\n",
      "-1.1029493469\n",
      "14\n",
      "-1.09343967893\n",
      "15\n",
      "-1.08223970292\n",
      "16\n",
      "-1.07013542181\n",
      "17\n",
      "-1.05712508561\n",
      "18\n",
      "-1.04357847197\n",
      "19\n",
      "-1.02952033582\n",
      "20\n",
      "-1.0152953123\n",
      "21\n",
      "-1.00265643601\n",
      "22\n",
      "-0.991962763461\n",
      "23\n",
      "-0.982899833026\n",
      "24\n",
      "-0.975239398484\n",
      "25\n",
      "-0.968754278092\n",
      "26\n",
      "-0.963271225264\n",
      "27\n",
      "-0.958635383632\n",
      "28\n",
      "-0.954710818165\n",
      "29\n",
      "-0.951403941164\n",
      "30\n",
      "-0.904488899219\n",
      "31\n",
      "-0.908341305476\n",
      "32\n",
      "-0.911698668435\n",
      "33\n",
      "-0.91462165151\n",
      "34\n",
      "-0.917163809435\n",
      "35\n",
      "-0.919372423229\n",
      "36\n",
      "-0.921289201123\n",
      "37\n",
      "-0.922950904367\n",
      "38\n",
      "-0.924389905445\n",
      "39\n",
      "-0.925634684841\n",
      "40\n",
      "-0.926710273052\n",
      "41\n",
      "-0.927638643701\n",
      "42\n",
      "-0.928439063569\n",
      "43\n",
      "-0.929128404472\n",
      "44\n",
      "-0.929721421669\n",
      "45\n",
      "-0.930231002256\n",
      "46\n",
      "-0.930668387004\n",
      "47\n",
      "-0.931043368289\n",
      "48\n",
      "-0.931364466466\n",
      "49\n",
      "-0.931639086742\n"
     ]
    }
   ],
   "source": [
    "from matplotlib.pyplot import *\n",
    "def H2_vqe(distance_range):\n",
    "    energy=np.zeros(len(distance_range))\n",
    "    for i in range(len(distance_range)):\n",
    "        print(i)\n",
    "        result=H2_vqe_subprocess(distance_range[i])\n",
    "        energy[i]=result.fun\n",
    "        print(energy[i])\n",
    "    return energy\n",
    "\n",
    "distance_range=np.linspace(0.25,2.5,50)\n",
    "energyvqe=H2_vqe(distance_range)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX8AAAD8CAYAAACfF6SlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xl8VPW9//HXd7JBQkJISCAhQBASERBkCyquiFVEUYu2\n1v3WpXUpXa6912K11l5tvf561Yu1brUFq3Zxg1KsIiJXbSGCrLKFncCEJWTfM/P9/XHCapDAJHOG\nOe/n4/F9nJOZw5xPDsN7Dt/5nu8x1lpERMRbfG4XICIi4afwFxHxIIW/iIgHKfxFRDxI4S8i4kEK\nfxERD1L4i4h4kMJfRMSDFP4iIh4U63YBR9O9e3ebm5vrdhkiIieVJUuW7LXWZhxru4gN/9zcXBYv\nXux2GSIiJxVjzNa2bKduHxERD1L4i4h4kMJfRMSDFP4iIh6k8BcR8SCFv4iIByn8RUQ8KOrCv6K+\ngp9/9HMKdxS6XYqISMSKuvAP2iAPL3iYj7d+7HYpIiIRK+rCP7WykYSgj5Jln7hdiohIxIrY6R1O\nlO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+GMMV2AN4EfWGsrj3y6lT8S1e+P\nYxyPDnt/KPxDVwwceiafA+w8dANrbam1tqHlxxeBkWGqLRId83h5ibW20lpb3bI+B4gzxnR3uawO\nY4yJwwm6V621b7WyiafeH8c6Hh35/lD4h+4zIM8Y088YEw9cB8w6dIMj+iwn4fTtedUs4OaWUR1n\nAhXWWr/bRbnFGNPTGGNa1gtw/k2WultVx2j5PX8HrLHW/s9RNvPM+6Mtx6Mj3x+x7fEiXmatbTbG\n3Au8hzPy52Vr7RfGmEeAxdbaWcAUY8wkoBnny79bXSu4gxljXscZodDdGFMM/AyIA7DWPgfMwRnR\nsQGoBf7NnUrDow3H4xrgLmNMM1AHXGdbhnlEobHATcBKY8yylsemAn3Ak++PthyPDnt/6ApfEREP\nUrePiIgHKfxFRDxI4S8i4kEKfxERD1L4i4h4kMJfRMSDFP4iIh6k8BcR8aD/DxlyHXMkfxMkAAAA\nAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1f50cdb5908>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "-0.93605491984427658"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from matplotlib.pyplot import *\n",
    "plot(distance_range,energy,'r',distance_range,energyvqe,'g')\n",
    "#plt.plot(x,y,'ro',x,y1,'g--')\n",
    "show()\n",
    "energy[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
